import cv2
import time
import os
import sys

# 获取当前文件所在的目录路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 将包的路径添加到sys.path列表中
#返回到实用工具目录下
current_dir = os.path.dirname(current_dir)
#进入到重命名与路径文件夹下
package_path = os.path.join(current_dir, '重命名与路径\\')

sys.path.append(package_path)

from 可视化获取文件路径 import *

# path = select_file()
path = select_mkdir()
save_path = select_mkdir()
c = 1

def mp4_jpgs(path,c):
    vido = cv2.VideoCapture(path)
    num_time = 20
    i = 0
    while True:
        try:
            _,frame = vido.read()
            save_path1 = os.path.join(save_path,str(c))
            save_path1 = save_path1+'.jpg'
            if i %num_time == 0:
                cv2.imwrite(save_path1,frame)
                print(save_path1)
                i = 0
            c+=1
            i+=1
        except:
            break
    return int(c)

if __name__ == "__main__":
    for i in os.listdir(path):       #对文件夹下面的文件进行遍历
        i = os.path.join(path,i)
        print(i)
        s1 = mp4_jpgs(i,c)
        c = int(c) + int(s1)
    print("已完成")

